package com.keyancompany.zhongbaopingtai.weight;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.keyancompany.zhongbaopingtai.R;
import com.keyancompany.zhongbaopingtai.utils.DensityUtils;

/**
 * Created by firefox on 2016/6/16.
 */
public class EmptyView extends LinearLayout {

    Drawable iconId;
    String hint;
    Context context;

    public EmptyView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.empty_view);
        iconId = a.getDrawable(R.styleable.empty_view_error_icon);
        hint = a.getString(R.styleable.empty_view_empty_hint);

        a.recycle();
        initView();
    }

    public EmptyView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.empty_view);
        iconId = a.getDrawable(R.styleable.empty_view_error_icon);
        hint = a.getString(R.styleable.empty_view_empty_hint);

        a.recycle();
        initView();
    }


    public void initView() {

        setOrientation(LinearLayout.VERTICAL);
        setGravity(Gravity.CENTER);
        setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        ImageView icon = new ImageView(context);
        icon.setLayoutParams(new LinearLayout.LayoutParams(DensityUtils.dp2px(context, 80), DensityUtils.dp2px(context, 120)));
        addView(icon);
        TextView hintTv = new TextView(context);
        hintTv.setText(hint);
        addView(hintTv);
    }

}
